/*GameDetailsPage.js*/

import React, {Component,PropTypes} from 'react';
import {connect} from 'dva';
import {routerRedux,withRouter } from 'dva/router';
import { Row,Col,Button,Card,Tabs,Popconfirm } from 'antd';
import moment from 'moment';
import DetailsOfGame from './DetailsOfGame';
import CompetitionRankings from './CompetitionRankings';

const TabPane = Tabs.TabPane;


class GameDetailsPage extends Component{
	state={
		"author":'',
	}
	GameClone=()=>{

	}
	
	GameDelete=(v)=>{
		console.log('GameDelete',v)
		this.props.dispatch({
			type:'privateGame/deletefundCompetition',
			payload:{
				id:v
			}
		})
	}
	componentWillMount() {
		const { login } = this.props;
		const authorities = login.userInfo.authorities;
		if(!_.isEmpty(login.userInfo)){
			login.userInfo.authorities.map((i)=>{
				if(i == 'ROLE_HEADQUARTERSDOCKING' || i == 'ROLE_ADMIN'){
					this.setState({
						"author":'0',
					})
				}else{
					this.setState({
						"author":'1',
					})
				}
			})
		}
		
	}
	render(){
		const { privateGame,login } = this.props;
		const {author} = this.state;
		
		console.log('GameDetails>>>1',privateGame.DetailsData,author)
		if(author=='1'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '草稿'){
			return(
				<Card>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
				    	{
					    	privateGame.DetailsData&&
					    	!_.isEmpty(privateGame.DetailsData)?<DetailsOfGame/>:null
				    	}
				    </TabPane>
				    <TabPane tab="排名" key="2" disabled>
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else if(author=='1'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '进行中'){
			return(
				<Card>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
					    <DetailsOfGame/>
				    </TabPane>
				    <TabPane tab="排名" key="2">
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else if(author=='1'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '已结束'){
			return(
				<Card>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
					    <DetailsOfGame/>
				    </TabPane>
				    <TabPane tab="排名" key="2">
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else if(author=='0'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '草稿'){
			return(
				<Card
					extra={
						<Row  type="flex" justify="end">
							<Col>
								<Popconfirm title="确定复制比赛?"  cancelText="取消" onConfirm={() => this.GameClone()}>
									<a >复制</a>
								</Popconfirm>
							</Col>&nbsp;|&nbsp;
							<Col>
								<Popconfirm title="确定删除比赛?"  cancelText="取消" onConfirm={() => this.GameDelete(privateGame.DetailsData.id)}>
									<a >删除</a>
								</Popconfirm>
							</Col>
						</Row>
					}
				>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
				    	{
					    	privateGame.DetailsData?<DetailsOfGame/>:null
				    	}
				    </TabPane>
				    <TabPane tab="排名" key="2" disabled>
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else if(author=='0'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '进行中'){
			return(
				<Card
					extra={
						<Row  type="flex" justify="end">

							<Col>
								<Popconfirm title="确定复制比赛?"  cancelText="取消" onConfirm={() => this.GameClone()}>
									<a >复制</a>
								</Popconfirm>
							</Col>&nbsp;|&nbsp;
							<Col>
								<Popconfirm title="确定删除比赛?"  cancelText="取消" onConfirm={() => this.GameDelete(privateGame.DetailsData.id)}>
									<a >删除</a>
								</Popconfirm>
							</Col>
						</Row>
					}
				>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
					    <DetailsOfGame/>
				    </TabPane>
				    <TabPane tab="排名" key="2">
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else if(author=='0'&&!_.isEmpty(privateGame.DetailsData)
			&&privateGame.DetailsData.status == '已结束'){
			return(
				<Card
					extra={
						<Row  type="flex" justify="end">

							<Col>
								<Popconfirm title="确定复制比赛?"  cancelText="取消" onConfirm={() => this.GameClone()}>
									<a >复制</a>
								</Popconfirm>
							</Col>&nbsp;|&nbsp;
							<Col>
								<Popconfirm title="确定删除比赛?"  cancelText="取消" onConfirm={() => this.GameDelete(privateGame.DetailsData.id)}>
									<a >删除</a>
								</Popconfirm>
							</Col>
						</Row>
					}
				>
					<Tabs defaultActiveKey="1" >
				    <TabPane tab="详情" key="1">
					    <DetailsOfGame/>
				    </TabPane>
				    <TabPane tab="排名" key="2">
				    	<CompetitionRankings/>
				    </TabPane>
				  </Tabs>
				</Card>
			)
		}else{
			return (
				<span>暂无数据</span>
			)
		}
	}
}


export default connect(({privateGame,login})=>({privateGame,login}))(GameDetailsPage)